package com.onlineshop.highgee.servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.onlineshop.highgee.dao.MyOrderDao;
import com.onlineshop.highgee.daoimpl.MyOrderDaoImpl;
import com.onlineshop.highgee.entity.MyOrder;

/**
 * Servlet implementation class AddOrderServlet
 */
@WebServlet("/AddOrderServlet")
public class AddOrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		MyOrder myOrder=new MyOrder();
		HttpSession session=request.getSession();
		try {
			double totals=(double)session.getAttribute("total");
			String userName=(String)session.getAttribute("user_name");
			long total=(long) totals;
			if(userName!=null) {
				myOrder.setOrder_number(Long.parseLong("12444343343"));
				myOrder.setOrder_adress("姹熻タ鐪�");
				myOrder.setOrder_total(total);
				myOrder.setOrder_state("1");
				Date date=new Date();
				java.sql.Date d2=new java.sql.Date(date.getTime());
				myOrder.setOrderDate(d2);
				myOrder.setOrder_phone("12323232323");
				myOrder.setOrder_name(userName);
				myOrder.setOrder_contact(userName);
				MyOrderDao myOrderDao=new MyOrderDaoImpl();
				myOrderDao.addMyOrder(myOrder);
				RequestDispatcher dispatcher = request.getRequestDispatcher("index.jsp");
				dispatcher.forward(request, response);
			}else {
				RequestDispatcher dispatcher = request.getRequestDispatcher("myaccount.jsp");
				dispatcher.forward(request, response);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
